package com.itgone.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

import com.itgone.exception.InitException;

public class AppUtil {
    private static Context sContext;

    public static void init(Activity context) {
        sContext = context;
    }

    public static void openActivity(Class<? extends Activity> clazz) {
        checkInit();
        Intent intent = new Intent(sContext, clazz);
        openActivity(intent);
    }

    public static void openActivity(Intent intent) {
        checkInit();
        sContext.startActivity(intent);
    }

    public static void finishActivity(Activity activity) {
        checkInit();
        activity.finish();
    }

    public static Context getContext() {
        checkInit();
        return sContext;
    }

    private static void checkInit() {
        if (sContext != null) {
            return;
        }
        throw new InitException("AppUtil 没有正确初始化");
    }
}
